/*
 * @Author: Hunter
 * @Date: 2022-02-18 14:06:59
 * @LastEditTime: 2022-02-18 17:55:06
 * @LastEditors: Hunter
 * @Description:
 * @FilePath: \template_server\src\utils\log.js
 * 可以输入预定的版权声明、个性签名、空行等
 */
const Logger = require("log4js");
Logger.configure({
  appenders: {
    out: {
      //设置控制台输出
      type: "console",
    },
    spiderLog: {
      type: "dateFile",
      filename: "src/logs/log",
      pattern: "yyyy-MM-dd.log",
      alwaysIncludePattern: true,
      maxLogSize: 10 * 1000 * 1000,
    },
  },
  categories: {
    default: {
      appenders: ["out", "spiderLog"],
      level: "all",
    },
  },
});

const appLogger = Logger.getLogger();
const logger = Logger.getLogger();
exports.useLogger = (app) => {
  app.use(
    Logger.connectLogger(appLogger, {
      level: "auto",
      format:
        "method: [:method] protocol: [:protocol] hostname: [:hostname] url: [:url] status: [:status] response-timems: [:response-timems] http-version: [:http-version] referrer:[:referrer] user-agent: [:user-agent] date: [:date] remote-addr: [:remote-addr] content-length: [:content-length]",
    })
  );
};
// const logType = ["info", "warn", "fail", "error", "log", "debug", "mark"];
exports.logger = logger;
